from manim import *


class VectorExample(Scene):
    def construct(self):
        plane = NumberPlane()
        vector_1 = Vector([1, 2])
        vector_2 = Vector([-5, -2])
        self.add(plane, vector_1, vector_2)


class VectorCoordinateLabel(Scene):
    """待标签的向量"""

    def construct(self):
        plane = NumberPlane()

        vec_1 = Vector([1, 2])
        vec_2 = Vector([-3, -2])
        label_1 = vec_1.coordinate_label()
        label_2 = vec_2.coordinate_label(color=YELLOW)
        vec_3 = Vector([-2, 0])
        arrow_4 = Arrow([1, 2, 0], [-2, 0, 0], color=GREEN)

        # self.add(plane, vec_1, vec_2, label_1, label_2)
        self.play(Create(plane))
        self.wait()
        self.play(Create(vec_1), Create(label_1))
        self.wait(2)
        self.play(Create(vec_2), Create(label_2))
        self.wait(2)
        # self.play(Create(arrow_4))
        self.play(ReplacementTransform(vec_2, arrow_4)) # 替换动画
        self.wait()
        self.play(Create(vec_3))
        self.wait()
